<?php
$params = array_merge(
    require __DIR__ . '/../../common/config/params.php',
//    require __DIR__ . '/../../common/config/params-local.php',
    require __DIR__ . '/params.php',
    require __DIR__ . '/params-local.php'
);

/*得到根域名 为了设置 根cookie*/
$host = $_SERVER['HTTP_HOST'];
// var_dump($_SERVER['HTTP_COOKIE']);
$host = explode(':', $host)[0];
$hostArr = explode('.', $host);
$tmp = count($hostArr);
if( !is_numeric($hostArr[count($hostArr)-1]) ){//最后一组不是数字，说明不是ip
    if($tmp > 2){
        $len = 2;
        if(($hostArr[$tmp-2] . $hostArr[$tmp-1] == 'comcn')
            or ($hostArr[$tmp-2] . $hostArr[$tmp-1] == 'netcn')
            or ($hostArr[$tmp-2] . $hostArr[$tmp-1] == 'govcn')){
            $len = 3;
        }
        foreach($hostArr as $k => $v){
            if($k < $tmp-$len){
                unset($hostArr[$k]);
            }
        }
    }
    $domain = '.' . implode('.', $hostArr);
}else{
    $domain = implode('.', $hostArr);
}
// var_dump($domain);


return [
    'id' => 'app-ticket',
    'basePath' => dirname(__DIR__),
    'controllerNamespace' => 'ticket\controllers',
    'bootstrap' => ['log'],
    'language'=>'zh-CN',
    'timeZone'=>'Asia/Shanghai',
    'modules' => [],
    'components' => [
        'request' => [
            'cookieValidationKey' => 'true',
            'csrfParam' => '_csrf-ticket',
            'enableCsrfValidation' => false,//关闭CSRF认证
            'enableCsrfCookie' => false,//关闭CSRF认证
        ],
        'user' => [
            'identityClass' => 'common\models\User',
            'enableAutoLogin' => true,
            'identityCookie' => ['name' => '_identity-ticket', 'httpOnly' => true],
        ],
        'session' => [
            // this is the name of the session cookie used for login on the cms
            'name' => 'session-ac',
            'class' => 'yii\redis\Session',
            'redis' =>'redis',
            'useCookies' => true,
            'keyPrefix'=>'ac.',
            'cookieParams' => [
                'secure' => false,
                'httpOnly' => true,
                'path' => '/',
                // 'domain' => '.super.com',
                'domain' => $domain,
                'lifetime' => 3600//过期时间
            ],
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],

        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
//                '/basic/open-app' => '/backend/basic/open-app',
            ],
        ],
        'redis' => [
            'class' => 'yii\redis\Connection',
            'hostname' => 'localhost',
            'port' => 6379,
            'database' => 0,
        ],

    ],


    'modules' => [
        'backend' => [
            'class' => 'ticket\modules\backend\Module',
        ],
        'frontend' => [
            'class' => 'ticket\modules\frontend\Module',
        ],
    ],


    'params' => $params,
];
